﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WP09S03_OfficeTracking
{
    public partial class MainForm : Form
    {

        private string loginUser;

        public string Login_User{
        get{
            return loginUser;
        }
        }

        public MainForm(String strEmployeeID)
        {
            InitializeComponent();
            this.loginUser = strEmployeeID;
        }


        private void MainForm_Load(object sender, EventArgs e)
        {

            //Control ctrl;
         //  MdiClient ctlMDI;

            foreach(Control ctrl in this.Controls ){

                try
                {
                   // ctlMDI = (MdiClient)ctrl;

                    //ctlMDI.BackColor = this.BackColor;

                  //  ctrl.BackColor = this.BackColor;

                    if (ctrl.GetType().IsInstanceOfType(new MdiClient()))
                    {
                        ctrl.BackColor = this.BackColor;
                    }
                   
                }
                catch (Exception ex) {
                    MessageBox.Show(ex.Message);

                }
            
            }

            frmWelcome fm = new frmWelcome();

            fm.ControlBox = false;
            fm.WindowState = FormWindowState.Maximized;

            showForm(fm);

            //perform email reminder notifications

            if (WP09S03_OfficeTracking.Properties.Settings.Default.EmailAutoNotify == true)
            {
                if (WP09S03_OfficeTracking.Properties.Settings.Default.EmailLastOperation.Date < System.DateTime.Today.Date)
                {
                    Controller.EmployeController ec = new Controller.EmployeController();
                    ec.RemindEmployeesOfOverdueItems();
                    //Set todays date, to avoid resending the same email within same day
                    WP09S03_OfficeTracking.Properties.Settings.Default.EmailLastOperation = System.DateTime.Today;
                    WP09S03_OfficeTracking.Properties.Settings.Default.Save();
                }

            }

        }



        private void testFormForTestingToolStripMenuItem_Click(object sender, EventArgs e)
        {

            //frmWelcome fm = new frmWelcome();

            //showForm(fm);

            test t = new test();
            t.MdiParent = this;
            t.Show();
            StatusLabel.Text = "Test form loaded";
            
            
        }
        private void disForm(Form pf)
        {
            Form[] fms = this.MdiChildren;
  

            foreach (Form f in fms)
            {
               
                if (f.Name != pf.Name)
                {
                    f.Dispose();
                }
            }

        }
        private void employeeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmEmployeeQuery f = new FrmEmployeeQuery();
            showForm(f);


        }

 
        private void bookEnToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmEquipment f = new FrmEquipment();
            showForm(f);
          
        }

        private void showForm(Form f) {
            ProgressBar.Value = 0;
            ProgressBar.Visible = true;
            ProgressBar.PerformStep();
            f.MdiParent = this;
            f.Show();
            disForm(f);
            ProgressBar.Value = ProgressBar.Maximum;
            f.Text = ((ParentClass.ParentForm)f).GetSubtitle();
            f.StartPosition = FormStartPosition.CenterScreen;

            StatusLabel.Text = f.Text + " Loaded!";
        }

        private void officeSuppliesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmSupplies f = new FrmSupplies();
            showForm(f);
        }

        private void issueTransactionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmIssueTransaction f = new FrmIssueTransaction();
            showForm(f);
        }

        private void returnTransactionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmReturnTransaction f = new FrmReturnTransaction();
            showForm(f);
        }

        private void stockReplenishTransactionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmReplenishTransaction f = new FrmReplenishTransaction();
            showForm(f);
        }

        private void booksAndEquipmentsIssueTransactionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmEquipmentIssue f = new FrmEquipmentIssue();
            showForm(f);
        }

        private void booksAndEquipmentsReturnTransactionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmEquipmentReturn f = new FrmEquipmentReturn();
            showForm(f);
        }

        private void officeSuppliesIssueTransactionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmSuppliesIssue f = new FrmSuppliesIssue();
            showForm(f);
        }

        private void officeSuppliesStockReplenishTransactionToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmSuppliesReplenish f = new FrmSuppliesReplenish();
            showForm(f);
        }

        private void reportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmReport f = new FrmReport();
            showForm(f);
        }

        private void userToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmUser f = new FrmUser();
            showForm(f);
        }

        private void employeeToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //frmWelcome f = new frmWelcome();
            //showForm(f);
            //DiagAddEmpoyee d=new DiagAddEmpoyee();
            //f.ShowDialog();
            FrmEmployee f = new FrmEmployee();
            showForm(f);
        }

        private void bookAndEquipmentToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //frmWelcome f = new frmWelcome();
            //showForm(f);
            FrmEquipment f = new FrmEquipment();
            showForm(f);

            f.btnCreate_Click(null, null);

            //DiagAddEquipment d = new DiagAddEquipment();
   
            //d.ShowDialog();
        }

        private void officeSuppliesToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            //frmWelcome f = new frmWelcome();
            //showForm(f);

            FrmSupplies f = new FrmSupplies();
            showForm(f);

            f.btnCreate_Click(null, null);


            //DiagAddSupplies d = new DiagAddSupplies();
            //d.ShowDialog();
        }

        private void categoryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //frmWelcome f = new frmWelcome();
            //showForm(f);
            FrmCategory f = new FrmCategory();
            showForm(f);
        }

        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmAboutBox f = new FrmAboutBox();
            f.ShowDialog();
        }

        private void contentsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Help.ShowHelp(this, this.helpProviderInfo.HelpNamespace);
        }
   

    }
}
